package com.zyy.smartcity1129.work;

import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.google.gson.JsonObject;
import com.zyy.smartcity1129.BaseFragment;
import com.zyy.smartcity1129.R;
import com.zyy.smartcity1129.data.JobInfo;
import com.zyy.smartcity1129.data.MyResumeQueryInfo;
import com.zyy.smartcity1129.data.ResultInfo;
import com.zyy.smartcity1129.data.UserInfo;
import com.zyy.smartcity1129.movie.MovieFragment;
import com.zyy.smartcity1129.util.Http;
import com.zyy.smartcity1129.util.PpUtil;
import com.zyy.smartcity1129.util.RvAd;

import java.util.List;

import okhttp3.RequestBody;

/**
 * @ClassName: ResumeFragment$
 * @Description: 作用
 * @Author: letquit
 * @CreateDate: 6/12/2021$
 * @Version: 1.0
 */
public class ResumeFragment extends BaseFragment {

    private TextView tv1;
    private TextView tv2;
    private TextView tv3;
    private TextView tv4;
    private TextView tv5;
    int userId;
    private LinearLayout lineRvPatient;
    private LinearLayout lineResume;
    private TextView tv6;
    private TextView tv7;
    private TextView tv8;
    private TextView tv9;
    private TextView tv10;
    private TextView tv11;
    private TextView tv12;
    private FrameLayout framePr2;
    private Button btnPR1;
    private EditText editPR6;
    private EditText editPR5;
    private EditText editPR4;
    private Spinner spPR1;
    private EditText editPR3;
    private EditText editPR2;
    private EditText editPR1;
    private FrameLayout framePr1;
    List<JobInfo.RowsBean> jobList;

    @Override
    protected int layId() {
        return R.layout.f_resume;
    }

    @Override
    protected String title() {
        return null;
    }

    @Override
    protected boolean back() {
        return false;
    }

    @Override
    protected Boolean bottom() {
        return false;
    }

    @Override
    protected void init(View iv) {
        WorkFragment.mutableLiveData.postValue("个人简历");
        initView(iv);
        th(() -> {
            UserInfo.UserBean userBean = Http.getInstance().get("/prod-api/api/common/user/getInfo", null, UserInfo.class, 1).getUser();
            userId = userBean.getUserId();
            MyResumeQueryInfo.DataBean myResumeQ = Http.getInstance().get("/prod-api/api/job/resume/queryResumeByUserId/" + userId, null, MyResumeQueryInfo.class, 1).getData();
            int resumeId = myResumeQ.getId();
            jobList = Http.getInstance().get("/prod-api/api/job/profession/list", null, JobInfo.class, 1).getRows();
            ui(() -> {
                tv1.setText("用户账号：" + userBean.getUserName());
                tv2.setText("用户昵称：" + userBean.getNickName());
                tv3.setText("    邮件：" + userBean.getEmail());
                tv4.setText("电话号码：" + userBean.getPhonenumber());
                tv5.setText("    性别：" + userBean.getSex());
                tv6.setText("工作经验：" + myResumeQ.getExperience());
                tv7.setText("最高学历：" + myResumeQ.getMostEducation());
                tv8.setText("现居住地：" + myResumeQ.getAddress());
                tv9.setText("    薪资：" + myResumeQ.getMoney());
                tv10.setText("自我描述：" + myResumeQ.getIndividualResume());
                tv11.setText("教育经历：" + myResumeQ.getEducation());
                int pId = myResumeQ.getPositionId();
                String pName = "无";
                for (int i = 0; i < jobList.size(); i++) {
                    if (pId == jobList.get(i).getId()) {
                        pName = jobList.get(i).getProfessionName();
                        break;
                    }
                }
                tv4.setText("期望职位：" + pName);
                lineResume.setOnClickListener(view -> {
                    initPP(resumeId);
                });
            });
        });
    }


    private void initPP(int resumeId) {
        PpUtil ppUtil = new PpUtil();
        View view = ppUtil.getP(requireContext(), R.layout.p_resume);
        framePr1 = (FrameLayout) view.findViewById(R.id.frame_pr1);
        editPR1 = (EditText) view.findViewById(R.id.editPR1);
        editPR2 = (EditText) view.findViewById(R.id.editPR2);
        editPR3 = (EditText) view.findViewById(R.id.editPR3);
        spPR1 = (Spinner) view.findViewById(R.id.spPR1);
        editPR4 = (EditText) view.findViewById(R.id.editPR4);
        editPR5 = (EditText) view.findViewById(R.id.editPR5);
        editPR6 = (EditText) view.findViewById(R.id.editPR6);
        btnPR1 = (Button) view.findViewById(R.id.btnPR1);
        framePr2 = (FrameLayout) view.findViewById(R.id.frame_pr2);
        btnPR1.setOnClickListener(view2 -> {
            String mostEducation = editPR2.getText().toString().trim();
            String education = editPR5.getText().toString().trim();
            String address = editPR3.getText().toString().trim();
            String experience = editPR1.getText().toString().trim();
            String individualResume = editPR6.getText().toString().trim();
            String money = editPR4.getText().toString().trim();
            String positionName = spPR1.getSelectedItem().toString();
            int positionId;
            switch (positionName) {
                case "java开发工程师":
                    positionId = 1;
                    break;
                case "设计":
                    positionId = 2;
                    break;
                case "外教":
                    positionId = 3;
                    break;
                case "前端工程师":
                    positionId = 4;
                    break;
                case "牙医":
                    positionId = 5;
                    break;
                case "全栈开发工程师":
                    positionId = 6;
                    break;
                case "前台经理":
                    positionId = 9;
                    break;
                case "服装模特":
                    positionId = 10;
                    break;
                case "快递员":
                    positionId = 11;
                    break;
                case "按摩师":
                    positionId = 12;
                    break;
                case "寝室长":
                    positionId = 13;
                    break;
                case "校园菜鸟驿站工作人员":
                    positionId = 14;
                    break;
                case "海德堡机长助手":
                    positionId = 15;
                    break;
                default:
                    Log.e("TAG", "switch Error");
                    positionId = 1;
            }
            JsonObject jsonObject = new JsonObject();
            jsonObject.addProperty("id", resumeId);
            jsonObject.addProperty("mostEducation", mostEducation);
            jsonObject.addProperty("education", education);
            jsonObject.addProperty("address", address);
            jsonObject.addProperty("experience", experience);
            jsonObject.addProperty("individualResume", individualResume);
            jsonObject.addProperty("money", money);
            jsonObject.addProperty("positionId", positionId);
            th(() -> {
                String result = Http.getInstance().get("/prod-api/api/job/resume", RequestBody.create(Http.m, jsonObject.toString()), ResultInfo.class, 3).getMsg();
                MyResumeQueryInfo.DataBean myResumeQ = Http.getInstance().get("/prod-api/api/job/resume/queryResumeByUserId/" + userId, null, MyResumeQueryInfo.class, 1).getData();
                ui(() -> {
                    tv6.setText("工作经验：" + myResumeQ.getExperience());
                    tv7.setText("最高学历：" + myResumeQ.getMostEducation());
                    tv8.setText("现居住地：" + myResumeQ.getAddress());
                    tv9.setText("    薪资：" + myResumeQ.getMoney());
                    tv10.setText("自我描述：" + myResumeQ.getIndividualResume());
                    tv11.setText("教育经历：" + myResumeQ.getEducation());
                    Toast.makeText(getContext(), result, Toast.LENGTH_SHORT).show();
                    ppUtil.closeP();
                });
            });
        });
        framePr1.setOnClickListener(view2 -> {
            ppUtil.closeP();
        });
        framePr2.setOnClickListener(view2 -> {
            ppUtil.closeP();
        });
    }

    private void initView(View iv) {
        lineRvPatient = (LinearLayout) iv.findViewById(R.id.lineRvPatient);
        tv1 = (TextView) iv.findViewById(R.id.tv1);
        tv2 = (TextView) iv.findViewById(R.id.tv2);
        tv3 = (TextView) iv.findViewById(R.id.tv3);
        tv4 = (TextView) iv.findViewById(R.id.tv4);
        tv5 = (TextView) iv.findViewById(R.id.tv5);
        lineRvPatient = (LinearLayout) iv.findViewById(R.id.lineRvPatient);
        lineResume = (LinearLayout) iv.findViewById(R.id.lineResume);
        tv6 = (TextView) iv.findViewById(R.id.tv6);
        tv7 = (TextView) iv.findViewById(R.id.tv7);
        tv8 = (TextView) iv.findViewById(R.id.tv8);
        tv9 = (TextView) iv.findViewById(R.id.tv9);
        tv10 = (TextView) iv.findViewById(R.id.tv10);
        tv11 = (TextView) iv.findViewById(R.id.tv11);
        tv12 = (TextView) iv.findViewById(R.id.tv12);
    }
}
